{include file='public/head' /}
{include file='public/left' /}
    <div class="main" style="padding:10px;">
        <div class="content">
            <span>商品列表</span>
          <a href="/admin/Index/add">添加</a>
          <a href="#" id="fh">返回商城</a>
            <div></div>
        </div>
        <form class="layui-form">
            <div class="layui-form-item" style="margin-top: 10px;">
                <div class="layui-input-inline">
                    <input class="layui-input" type="text" name="keyword">
                </div>
                <button class="layui-btn  layui-btn-primary"><i class="layui-icon">&#xe615</i>搜索</button>
            </div>
        </form>
        <table class="layui-table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>商品名称</th>
                    <th>分类</th>
                    <th>原价</th>
                    <th>折扣</th>
                    <th>现价</th>
                    <th>库存</th>
                    <th>状态</th>
                    <th>添加时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {volist name='right' id='right_v'}
                    <tr>
                        <td>{$right_v.id}</td>
                        <td>{$right_v.title}</td>
                        <td>{$right_v['cat']}</td>
                        <td>{$right_v.price}</td>
                        <td>{$right_v.discount}</td>
                        <td>
                            {if $right_v.discount!=0}
                                {$right_v.price*$right_v.discount/10}
                            {else/}
                                {$right_v.price}
                            {/if}
                        </td>
                        <td>{$right_v.stock}</td>
                        <td>{if $right_v.status==1}开启{else/}关闭{/if}</td>
                        <td>{$right_v.add_time|date='Y-m-d'}</td>
                        <td><button class="layui-btn layui-btn-xs" 
                            onclick="edit({$right_v.id})">修改</button>
                            <button class="layui-btn layui-btn-xs layui-btn-danger" 
                            onclick="del({$right_v.id})">删除</button></td>
                    </tr>
                {/volist}
            </tbody>
        </table>
        <div>{$list|raw}</div>
    </div>
<script type="text/javascript">
    function add(){
            layer.open({
            title: '添加',
            type:2,
            shade:0.3,
            area:['480px','440px'],
            content: '/admin/index/add'
        });  
    }
    function edit(id){
        layer.open({
            title: '修改',
            type:2,
            shade:0.3,
            area:['480px','440px'],
            content: '/admin/index/edit?id='+id
        });  
    }
    function del(id){
        layer.confirm('确定要删除吗？', {
            icon:3,
            btn: ['确定','取消']
        }, function(){
            $.post('/admin/index/del',{'id':id},function(res){
                if(res.code>0){
                    layer.alert(res.msg,{icon:2});
                }else{
                    layer.msg(res.msg);
                    setTimeout(function(){window.location.reload();},1000);
                }
            },'json');
        });
    }
    var a = document.getElementById("fh");
    a.onclick=function(){
        var r = confirm("确认返回前端页面嘛？")
        if(r==true){
            location.href='/index/index';
        }else {

        }
    }
</script>
{include file='public/bottom' /}